//index.js
//获取应用实例
const { getUserSession, wxUserInfo, wxUserPhone } = require('../../utils/user.js');
const app = getApp()
let self
Page({
  data: {
		imgUrls: [
			{
				imgUrl: '/assert/imgs/banner1.jpg',
				swiperUrl: '/pages/schoollist/schoollist?filters=banner&area=407',
				navType: 'tabbar'
			},
			{
				imgUrl: '/assert/imgs/banner2.jpg',
				swiperUrl: '/pages/list-page/list-page?filters=address&title=深圳&areaId=948',
				navType: 'pages'
			},
			{
				imgUrl: '/assert/imgs/banner3.jpg',
				swiperUrl: '/pages/list-page/list-page?filters=major&title=心理学&matjorId=1274',
				navType: 'pages'
			}
		],

    userInfo: {},
    hasUserInfo: false,
		inputShowed: false,
		inputVal: ""
  },
  onLoad: function () {
		self = this;
		//self.getUserInfo()  // 获取用户信息
	
  },
	onShow: function () {	
	},
  // getUserInfo: function(e) {
	// 	wx.getSetting({
	// 		success: (res) => {
	// 			if (res.authSetting['scope.userInfo']) {
	// 				getUserSession().then((sessionid, openid) => {  // 获取用户的sessionid 和 openid
	// 					app.wxAuth(true)
	// 				})
	// 			}
	// 		}
	// 	})
  // },
	onSchoolList: function(e) {
		let filtertype = e.currentTarget.dataset.filtertype;
		let filtertit = e.currentTarget.dataset.filtertit
		wx.reLaunch({
			url: '/pages/schoollist/schoollist?filters=' + filtertype + '&title=' + filtertit
		})
	},
	onNavigateTo: function (e) {
		let filtertype = e.currentTarget.dataset.filtertype;
		let filtertit = e.currentTarget.dataset.filtertit
		wx.navigateTo({
			url: '/pages/list-page/list-page?filters=' + filtertype + '&title=' + filtertit
		})
	},
	onClassify: function (e) {
		let filtertype = e.currentTarget.dataset.filtertype;
		let filtertit = e.currentTarget.dataset.filtertit
		wx.navigateTo({
			url: '/pages/classify/classify?filters=' + filtertype + '&title=' + filtertit
		})
	},
	navFaq: function (e) {
		let filtertype = e.currentTarget.dataset.filtertype;
		let filtertit = e.currentTarget.dataset.filtertit
		wx.navigateTo({
			url: '/pages/form-page/sign-up/sign-up?filters=' + filtertype + '&title=' + filtertit
		})
	},
	navTest: function (e) {
		let filtertype = e.currentTarget.dataset.filtertype;
		let filtertit = e.currentTarget.dataset.filtertit
		wx.reLaunch({
			url: '/pages/test-page/test-page'
		})
	},
	onDetails: function (e) {
		let detailtype = e.currentTarget.dataset.detailtype;
		let detailid = e.currentTarget.dataset.detailid;
		let newsId = e.currentTarget.dataset.newsid;
		wx.navigateTo({
			url: '/pages/rules-detail/rules-detail?detailtype=' + detailtype + '&detailid=' + detailid + '&newsId=' + newsId
		})
	},
	showInput: function () {
		this.setData({
			inputVal: "",
			inputShowed: true
		});
	},
	hideInput: function () {
		this.setData({
			inputVal: "",
			inputShowed: false
		});
	},
	clearInput: function () {
		this.setData({
			inputVal: ""
		});
	},
	inputTyping: function (e) {
		this.setData({
			inputVal: e.detail.value
		});
	},
	search(e) {
		this.setData({
			inputVal: e.detail.value || '',
			inputShowed: false
		});
		wx.navigateTo({
			url: '/pages/list-page/list-page?filters=general&title=招生简章&searchVal=' + e.detail.value
		})
	},
	onShareAppMessage: function (res) {
		return {
			title: '在职研究生网',
			path: '/pages/index/index'
		}
	},
	onSwiperTap(e) {
		let url = e.target.dataset['url']
		let navType = e.target.dataset['navtype']
		if (navType == "tabbar") {  // 是否跳转 tabbar 页面
			wx.reLaunch({
				url,
			})
		} else {
			wx.navigateTo({
				url,
			})
		}
		
	},
	bindblur(e) {
		this.setData({
			inputShowed: false,
		})
	}
})
